/*
 * Date：10/23/18 10:08 PM 
 * Author: guomw
 *
 */

package org.elanfox.intellicommunity.biz.repository.resident;

import org.elanfox.intellicommunity.biz.entity.resident.StructurePO;
import org.elanfox.intellicommunity.data.base.base.JpaSearchableRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 社区结构Repository
 *
 * @author loutianxi
 * @date 2019-12-04
 */
@Repository
public interface StructureRepository extends JpaSearchableRepository<StructurePO, Integer> {

    List<StructurePO> findByPStructureIdAndEnableIsTrue(Integer strId);

    List<StructurePO> findByEnableIsTrueOrderByItemSort();

    @Query("update StructurePO c set c.enable=?2 where c.structureId=?1")
    @Modifying(clearAutomatically = true)
    @Transactional(rollbackFor = RuntimeException.class)
    int updateEnableById(Integer strId, boolean enable);

    List<StructurePO> findByEnableIsTrueAndPStructureIdOrderByItemSort(Integer pStrId);
}
